<template>
	<div>
		<jk-table border :data="tableData" :height="height" :loading="loading">
			<vxe-column
				v-for="(item, index) in tableColumnList"
				:key="index"
				:title="item.title"
				:align="item.align"
				:field="item.keyName"
				:sortable="item.sortable"
				:fixed="item.fixed ? item.fixed : ''"
				:min-width="item.minWidth"
				:width="item.width"
			>
				<template slot-scope="scope">
					<span v-if="item.keyName === 'deviceRecordNumber'" @click="onMachine(scope.row)">{{ scope.row.deviceRecordNumber }}</span>
					<span v-else>{{ scope.row[item.keyName] }}</span>
				</template>
			</vxe-column>
		</jk-table>
		<detail-dialog
			:search-params="searchParams"
			:data-item="selectedRowItem"
			:dialog-state="detailDialogState"
			@on-visible-change="onVisibleChange"
		></detail-dialog>
	</div>
</template>

<script>
    import detailDialog from './detail-dialog';
    import { systemUserColumnConfigGet } from '../../../../api/system/column-config';
    export default {
        components: { detailDialog },
        props: {
            tableData: {
                type: Array,
                default() {
                    return [];
                }
            },
            searchParams: {
                type: Object,
                default() {
                    return {};
                }
            },
            height: {
                type: [String, Number],
                default: 0
            },
            loading: {
                type: Boolean,
                default: false
            }
        },
        data() {
            return {
                tableColumnList: [],
                selectedRowItem: {},
                detailDialogState: false
            };
        },
        methods: {
            getMenuColumnListRequest() {
                return systemUserColumnConfigGet({ path: 'DeclineProductionMonitoringHistory', filterShow: true }).then(res => {
                    if (res.data.status === 200) {
                        this.tableColumnList = res.data.res.columnConfigList && res.data.res.columnConfigList.length ? res.data.res.columnConfigList[0].itemList : [];
                    }
                });
            },
            onVisibleChange(e) {
                this.detailDialogState = e;
            },
            onMachine(rowItem) {
                this.selectedRowItem = rowItem;
                if (rowItem.deviceRecordNumber.includes('LT') || rowItem.deviceRecordNumber.includes('lt')) {
                    // this.detailDialogState = true;
                }
            }
        },
        mounted() {
            this.getMenuColumnListRequest();
        }
    };
</script>
